<!DOCTYPE html>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <title>Layui</title>
    <base href="${pageContext.request.scheme}://${pageContext.request.serverName}:${pageContext.request.serverPort}${pageContext.request.contextPath}/"/>
    <link rel="icon" href="static/images/favicon.ico">
    <link rel="stylesheet" href="static/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="static/css/layuimini.css" media="all">
    <link rel="stylesheet" href="static/css/themes/default.css" media="all">
    <link rel="stylesheet" href="static/lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
</head>
<body>

<%--查询条件--%>
<fieldset class="layui-elem-field layui-field-title site-demo-button" style="margin-top: 50px;">
    <legend>查询条件</legend>
</fieldset>
<form class="layui-form layui-form-pane" action="">
    <div class="layui-input-inline">

        <div class="layui-inline">
            <label class="layui-form-label">保单号</label>
            <div class="layui-input-inline">
            <input name="warrantyId" class="layui-input" id="warrantyId" autocomplete="off">
            </div>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label">被保人</label>
            <div class="layui-input-inline">
            <input name="recognizeeName" class="layui-input" id="recognizeeName" autocomplete="off">
            </div>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label">车牌号</label>
            <div class="layui-input-inline">
            <input name="licenseId" class="layui-input" id="licenseId" autocomplete="off">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <button type="button" class="layui-btn" data-type="reload" id="cx">查询</button>
        <button class="layui-btn layui-btn-warm" type="button" id="cz">重置</button>
    </div>
</form>
<%--查询条件--%>


<%--修改--%>
<div id="updpolicies" style="display: none" >
    <form class="layui-form layui-form-pane" action="" lay-filter="insuredFrom">
        <div class="layui-form-item" style="margin-left: 8px">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">保单号</label>
                    <div class="layui-input-inline">
                        <input name="warrantyId" class="layui-input" type="text" readonly="readonly" autocomplete="off" lay-verify="required" style="width: 120px">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">车牌号</label>
                    <div class="layui-input-inline">
                        <input name="licenseId" class="layui-input" type="text" autocomplete="off" style="width: 120px">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">车主</label>
                    <div class="layui-input-inline">
                        <input name="carOwnerName" class="layui-input" type="text" autocomplete="off" style="width: 90px">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
<%--                <div class="layui-inline">
                    <label class="layui-form-label">已行驶公里</label>
                    <div classl="layui-input-inline">
                        <input name="mileage" class="layui-input" type="text" autocomplete="off" style="width: 90px">
                    </div>
                </div>--%>
                <div class="layui-inline">
                    <label class="layui-form-label">颜色</label>
                    <div class="layui-input-inline">
                        <input name="carColor" class="layui-input" type="text" autocomplete="off" style="width: 90px">
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-form-item" style="text-align: center">
            <button type="button" id="btnSubmit" class="button_login layui-btn" lay-submit lay-filter="btnSubmit">完成</button>
            <%--<button class="layui-btn" id="doSumbit" lay-submit="doSumbit" type="button"  lay-filter="doSumbit">完成</button>--%>
        </div>
    </form>
</div>


<%--保单信息列表--%>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
    <legend>保单信息列表</legend>
</fieldset>
<script id="toolbarDemo"  type="text/html">
    <div id="layerDemo"  class="layui-btn-container site-demo-button">
        <button class="layui-btn" data-method="setTop1">添加保单</button>
        <button class="layui-btn layui-btn-sm" lay-event="getCheckData2" id="dele">删除保单</button>
        <%--<button class="layui-btn layui-btn-sm" lay-event="getCheckData3" data-method="setTop2">修改保单</button>--%>
        <%--<button class="layui-btn layui-btn-sm" lay-event="getCheckData4" id="sh">保单审核</button>--%>
    </div>
</script>
<table class="layui-hide" id="test" lay-filter="test"></table>

<%--保单信息列表--%>



<script src="static/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="static/lib/jquery-3.4.1/jquery-3.4.1.min.js"></script>
<script src="static/js/lay-config.js" charset="utf-8"></script>
<script>
    var warrantyId = "";
    var abc ="";
    layui.use(['jquery','form', 'layedit', 'laydate','layer'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate
            ,$ = layui.jquery
            ,layer = layui.layer;
        //日期
        laydate.render({
            elem: '#date'
        });
        laydate.render({
            elem: '#date1'
        });

        //创建一个编辑器
        var editIndex = layedit.build('LAY_demo_editor');
        //自定义验证规则
        //监听指定开关
        /*form.on('switch(switchTest)', function(data){
            layer.msg('开关checked：'+ (this.checked ? 'true' : 'false'), {
                offset: '6px'
            });
            layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
        });
        //监听提交
        form.on('submit(demo1)', function(data){
            layer.alert(JSON.stringify(data.field), {
                title: '最终的提交信息'
            })
            return false;
        });*/

        var active = {

            setTop1: function () {
                var that = this;
                //多窗口模式，层叠置顶
                layer.open({
                    type: 2 //此处以iframe举例
                    , title: '新增表单信息'
                    , area: ['900px', '900px']
                    , area:['85%','85%']
                    , shade: 0
                    , maxmin: true
                    , content: '/toaddwarr'
                    , zIndex: layer.zIndex //重点1
                    , success: function (layero) {
                        layer.setTop(layero); //重点2
                    }
                });
            },
            setTop2: function () {
                $("[name='warrantyId']").val(abc.warrantyId);
                $("[name='recognizeeId']").val(abc.recognizeeId);
                $("[name='licenseId']").val(abc.licenseId);
                $("[name='frameId']").val(abc.frameId);
                $("[name='sailint']").val(abc.sailint);
                $("[name='makeId']").val(abc.makeId);
                $("[name='engineId']").val(abc.engineId);
                $("[name='makeId']").val(abc.makeId);
                $("[name='customersSum']").val(abc.customersSum);
                $("[name='carOwnerName']").val(abc.carOwnerName);
                $("[name='placemanLength']").val(abc.placemanLength);
                $("[name='mileage']").val(abc.mileage);
                $("[name='carColor']").val(abc.carColor);
                $("[name='vpDollar']").val(abc.vpDollar);


                var that = this;
                //多窗口模式，层叠置顶
                layer.open({
                    type: 1 //此处以iframe举例
                    , title: '修改表单信息'
                    , area: ['900px', '900px']
                    , area:['70%','85%']
                    , shade: 0
                    , maxmin: true
                    ,shadeClose: true
                    , content: $('#updpolicies')
                });
            }
        }
        $('#layerDemo .layui-btn').on('click', function(){
            var othis = $(this), method = othis.data('method');
            active[method] ? active[method].call(this, othis) : '';
        });




        /*修改*/
        form.on('submit(btnSubmit)', function (data) {
            console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
            var aaa = data.field;
            $.ajax({
                url:'/warrantyInfo/updwarr',
                type:'post',
                dataType:"json",
                data :JSON.stringify(aaa),
                //async:"true",
                contentType: 'application/json;charset=UTF-8',//指定消息请求类型
                success : function(data1) {
                    //alert(data1);
                    // console.log(data1);
                     if(data1>0){
                         alert("修改成功");
                         setTimeout(function () {
                             window.location.reload();
                         }, 150);
                     }else{
                         alert("修改失败");
                     }

                }
            });
        })

    });

/*保单信息*/
    layui.use('table', function(){
        var table = layui.table;

        var aa=table.render({
            elem: '#test'
            ,url:'/warrantyInfo/seleAll'
            ,toolbar: '#toolbarDemo'
            ,cols: [ [
                {field:'warrantyid',  title: '保单号'}
                ,{field:'recognizeeName',  title: '被保人'}
                ,{field:'licenseid',  title: '车牌号'}
                ,{field:'insurancebegintime',  title: '起保时间'}
                ,{field:'insuranceendtime',  title: '终保时间'}
                ,{field:'warrantystate',  title: '保单状态',templet:function (d) {
                        if (d.warrantystate == 1){
                            return "保期内";
                        }else if(d.warrantystate == 2){
                            return "注销";
                        }
                    }}
                /*,{field:'premiumMoney', width:135, title: '保费金额'}*/
                ,{field:'warrantytype', width:135, title: '保单类型',templet:function (d) {
                        if (d.warrantytype == 1){
                            return "交强险";
                        }else if(d.warrantytype == 2){
                            return "商业险";
                        }
                    }}
                /*,{field:'warrantyState', width:135, title: '保单状态',templet:function (d) {
                        if (d.insuranceEndTime > '2020-7-20'){
                            return "保期内";
                        }else{
                            return "注销";
                        }
                    }}*/
            ] ]
            ,id:'claims'
            ,page: true
        });

        var $ = layui.$, active = {
            reload: function(){
                var warrantyId = $('#warrantyId');
                var recognizeeName = $('#recognizeeName');
                var licenseId = $('#licenseId');
                //执行重载
                table.reload('claims', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                         warrantyid: warrantyId.val(),
                         recognizeeName: recognizeeName.val(),
                         licenseid: licenseId.val()
                        /*key: {
                            warrantyId: warrantyId.val(),
                            recognizeeId: recognizeeId.val(),
                            licenseId: licenseId.val()
                        }*/
                    }
                }, 'data');
            }
        };

        $('#cx').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });


        //头工具栏事件
        table.on('row(test)', function(obj){
            abc = obj.data;
            warrantyId = abc.warrantyid;
            data1 = abc.insuranceEndTime;
            //标注选中样式
            obj.tr.addClass('layui-table-click').siblings().removeClass('layui-table-click');
        });

        layui.$('#dele').on('click', function(){
            console.log("1");
            layer.confirm('真的删除行么', function(index){
                console.log("2");
                $.ajax({
                    url:'/warrantyInfo/delewarr',
                    type:'get',
                    /*data:'settlementAudit='+data.settlementAudit+'&settlementId='+settlementId ,*/
                    dataType:"json",
                    data : "warrantyid="+warrantyId,
                    //async:"true",
                    contentType: 'application/json;charset=UTF-8',//指定消息请求类型
                    success : function(data) {
                        //window.location.reload();
                        if(data>0){
                            alert("删除成功");
                            setTimeout(function () {
                                window.location.reload();
                            }, 150);
                        }else{
                            alert("删除失败");
                        }
                    }
                });
            });

            return false;
        });

        /*layui.$('#sh').on('click', function(){
            if(data1>'2020-7-14'){
                table.warrantyState1.html="保期内";
            }else{
                table.warrantyState1.html="注销";
            }
        });*/

    });



    /*新增*/



</script>

</body>
</html>